[contents] [prev] [next] [top] [bottom] (16 out of 17)

Compound Expressions

Compound expressions, sometimes called block expressions or just blocks, are simply a series of complete expressions surrounded by parentheses. Those expressions can be on separate lines, on the same line separated by semicolons, or in any combination, just like normal expressions.

( 
expression
expression
. . .
)
Compound expressions allow you to control the order in which an expression is evaluated. A compound expression can also be used to group several expressions into what appears, from the point of view of surrounding expressions, as a single expression. Thus, you can use a compound expression anywhere a single expression would work. The result of evaluating a compound expression is the value of the last expression in the block, unless a specific exit or return value has been specified using a block control expression. See "Conditionals and Loops" on page 79, for information on using compound expressions with block control expressions such as exit and continue.

A compound expression yields an object, just like a regular expression. A compound expression can be used in place of most ScriptX expressions.

-- globals cannot be explicitly declared in a block
global m:0, n:1 
-- a compound expression, because it is enclosed in parentheses
t := (if m < n then m else n) 
0

(
x := "string1"
y := "string2"
print (x + y)
)
"string1string2"
OK

If the final statement in a compound expression is a local declaration, it returns undefined rather that the value of the local declaration. Note the difference between the first and second expressions.

global y := (local x := 10)
undefined
global y := (x := 10)
-- ** Warning: Undeclared global x
10


This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.

Copyright 1996 Apple Computer, Inc. All Rights Reserved.